﻿<div id = "user_details">

    <?php

    $query = "select * from USERS where user_id = ".$user_id; //επιλογή του χρήστη με βάση το id το παίρνει με _GET
    $results = $set->qry($query);
    $row = mysql_fetch_assoc($results);

    ?>

    <div style="float:left;">
        <form action=<?php echo "users.php?id=".$user_id."&action=edit"?> method="post">

        <table class="table_search">
            <tr>
                <td>Username</td>
                <td><input id="username" class="search_input" type="text" name="username" value="<?php echo $row['user_name'];?>"></td>
            </tr>
            <tr>
                <td>First name</td>
                <td><input id="fname" class="search_input" type="text" name="fname" value="<?php echo $row['user_fname'];?>"></td>
            </tr>
            <tr>
                <td>Last name</td>
                <td><input id="lname" class="search_input" type="text" name="lname" value="<?php echo $row['user_lname'];?>"></td>
            </tr>
            <tr>
                <td>Gender</td>
                <td><input id="gender" class="search_input" type="text" name="gender" value="<?php echo $row['user_gender'];?>"></td>
            </tr>
            <tr>
                <td>Location</td>
                <td><textarea id="location" class="search_input" name="location" rows="5"><?php echo $row['user_autocomplete'];?></textarea></td>
            </tr>
            <tr>
                <td><label>User Role</label></td>
                <?php selectRole($row['user_level'])?>
            </tr>
            <tr>
                <td>Phone 1</td>
                <td><input id="phone1" class="search_input" type="text" name="phone1" value="<?php echo $row['user_phone1'];?>"></td>
            </tr>
            <tr>
                <td>Phone 2</td>
                <td><input id="phone2" class="search_input" type="text" name="phone2" value="<?php echo $row['user_phone2'];?>"></td>
            </tr>
            <tr>
                <td>Email</td>
                <td><input id="email" class="search_input" type="text" name="email" value="<?php echo $row['user_email'];?>"></td>
            </tr>
            <tr>
                <td>Web site</td>
                <td><input id="website" class="search_input" type="text" name="website" value="<?php echo $row['user_website'];?>"></td>
            </tr>
            </table>
        <table class="table_search">
            <tr>
                <td>
                    <input type="image" src="imgs/edit-icon.png"alt="edit" title="edit" width="50px">
                </td>
                <td>
                    <a href=<?php echo "users.php?id=".$user_id."&action=delete"?>><img src="imgs/delete_icon.png" alt="delete" title="delete" width="50px"></a>
                </td>
                <td>
                    <a href=<?php echo "users.php?id=".$user_id."&action=new"?>><img src="imgs/new_icon.png" alt="new" title="new" width="50px"></a>
                </td>
            </tr>
        </table>
        </form>
    </div>

    <?php
    $query_ads = "SELECT ADS.ad_id, ADS.ad_title, ADS.ad_desc, FAVOURITES.fav_id
              FROM ADS
              INNER JOIN FAVOURITES
              ON FAVOURITES.fav_adid = ADS.ad_id
              WHERE FAVOURITES.fav_userid = ".$user_id; //ερώτημα για τις favorite αγγελίες του χρήστη

    $results = $set->qry($query_ads);
    ?>

    <div align="center" style="float:right; width:50%; ">
            <table id="table_fav_ads">
                <h3 style="">Favorites Advertises</h3>
                <th>Title</th><th>Description</th><th>Tools</th>
                <?php
                while($row = mysql_fetch_assoc($results))
                {
                    $ad_id = $row['ad_id'];
                    $fav_id = $row['fav_id'];
                    ?>
                    <tr>
                        <td><?php echo $row['ad_title'] ?></td>
                        <td><?php echo $row['ad_desc'] ?></td>
                        <td>
                            <a href=<?php echo "advertisements.php?id=".$ad_id."&action=view"?>><img src="imgs/view-icon.png" alt="view" title="View" width="25px"></a>
                            <a href=<?php echo "users.php?id=".$fav_id."&action=delete_fav"?>><img src="imgs/delete_icon.png" alt="delete" title="delete" width="25px"></a>
                        </td>
                    </tr>
                    <?php }?>
            </table>
</div>

<?php
    function selectRole($role){
        if($role == 1){
            echo '<td><select id="role" class="search_input" type="text" name="role">
                    <option value="1" selected>Administrator</option>
                    <option value="4">Individual</option>
                </select> </td>';
    }
        else{
            echo '<td><select id="role" class="search_input" type="text" name="role">
                    <option value="1">Administrator</option>
                    <option value="4" selected>Individual</option>
                </select> </td>';
        }
    }

?>